﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Skyhook.Core.Xml
{
    class XmlDocumentsCacheEnumerator : IEnumerator<XmlDocumentWithFileName>
    {
        int CurrentPosition = -1;
        Dictionary<string, XmlDocumentWithFileName> Documents = null;

        public XmlDocumentsCacheEnumerator(Dictionary<string, XmlDocumentWithFileName> documentslist)
        {
            Documents = documentslist;
        }

        XmlDocumentWithFileName IEnumerator<XmlDocumentWithFileName>.Current
        {
            get 
            {
                if (CurrentPosition < Documents.Count)
                {
                    return Documents.Values.ElementAt(CurrentPosition);
                }
                return null;
            }
        }

        public void Dispose()
        {
        }

        object IEnumerator.Current
        {
            get
            {
                if (CurrentPosition < Documents.Count)
                {
                    return Documents.Values.ElementAt(CurrentPosition);
                }
                return null;
            }
        }

        public bool MoveNext()
        {
            CurrentPosition++;
            if (CurrentPosition >= Documents.Count)
            {
                return false;
            }
            return true;
        }

        public void Reset()
        {
            CurrentPosition = -1;
        }
    }
}
